<template>
  <div id="app" @click="onPageClick">
    <router-view></router-view>
  </div>
</template>

<script setup>
const { VITE_APP_TITLE } = import.meta.env
document.title = VITE_APP_TITLE

import { usePageStore } from '@/pinia/page.js'
import {onBeforeUnmount, onMounted, onUnmounted} from "vue";
import auth from '@/utils/auth.js'

const store = usePageStore()
const onPageClick = () => {
  store.setClickTimeStamp()
}


let _beforeUnload_time = '';
let _gap_time = '';


const beforeunloadHandler = (e) => {
  _beforeUnload_time = new Date().getTime();
  //e.returnValue = '关闭提示'; 弹窗
};
const unloadHandler = (e) => {
  _gap_time = new Date().getTime() - _beforeUnload_time;
  //判断是窗口关闭还是刷新
  if (_gap_time <= 5) {
    auth.removeToken()
  }
};

onMounted(() => {
  window.addEventListener("beforeunload", (e) => beforeunloadHandler(e));
  window.addEventListener("unload", (e) => unloadHandler(e));

})

onUnmounted(() => {
  window.removeEventListener("beforeunload", (e) => beforeunloadHandler(e));
  window.removeEventListener("unload", (e) => unloadHandler(e));
})


let tButton = document.getElementsByClassName('t-button')
tButton.onmousedown = () => {
  console.log('mouse down')
}
console.log('tButton', tButton)
// tButton.forEach(item => {
//   console.log('tButton', item)
// })
</script>

<style lang="scss" scoped>
#app {
  width: 100%;
  height: 100%;
}
</style>
